<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.wxtf.platform.plugins.user.*"%>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
	UserBean user = (UserBean)request.getSession().getAttribute("userBean");
	
	String _db = user.getDbType();
	String userName = user.getUserrelName();
	String org = user.getCurOrgName();
	String org_id = user.getCurOrgId();
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<base href="<%=basePath%>"/>
		<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
		<meta http-equiv="pragma" content="no-cache"/>
		<meta http-equiv="cache-control" content="no-cache"/>
		<meta http-equiv="expires" content="0"/>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<title>药具随访汇总</title>

		<link type="text/css" rel="stylesheet" href="ligerUI/skins/Aqua/css/ligerui-all.css" />
		<link type="text/css" rel="stylesheet" href="ligerUI/skins/<%=user.getUserCss()%>/css/ligerui-all.css" />
		<link type="text/css" rel="stylesheet" href="ligerUI/skins/ligerui-icons.css" />
		<link type="text/css" rel="stylesheet" href="resource/css/style.css" />

		<script type="text/javascript" src="js/jquery/jquery-1.7.2.js"></script>
		<script type="text/javascript" src="ligerUI/js/core/base.js"></script>
		<script type="text/javascript" src="ligerUI/js/ligerui.min.js"></script>
		<script type="text/javascript" src="js/common.js"></script>
		<script type="text/javascript" src="js/validata.js"></script>

		<script type="text/javascript" src="ligerUI/js/plugins/ligerGrid.js"></script>
<script type="text/javascript">
var _db = '<%=_db%>';
var userName = '<%=userName%>';
var org = '<%=org%>';
_jsonObj.classname = "com.wxtf.platform.main.report.TmaMedicineVistorReport";
_jsonObj.methodname = "queryPage";
var manager;
var per;
$(function(){
	var shijian = getCurDateTime();
	$("#tianbaoriqi").val(shijian);
	$("#tianbaojigou").val(org);
	$("#tianbaoren").val(userName);
	quarter(shijian);
	manager = $("#grid").ligerGrid({
		url: _url, parms: _jsonObj, width: '100%', height: '80%',enabledSort:false, enabledEdit: true,
		usePager: false, rownumbers: true, alternatingRow: false, async:false,
		columns: [
			{ display: 'tmad_id', name: 'tmad_id',width:1, hide:true},
			{ display: '产品名称', name: 'tmad_name',width:100, align:'left'},
			{ display: '生产企业', name: 'tmad_company_name', width:100, align:'left' },
			{ display: '批号', name: 'tmad_batch_code',width:100, align:'left'},
			{ display: '服药人数', name: 'renshu',width:100, align:'left'},
			{ display: '代码', name: 'tmgd_code',width:100 },
			{ display: '例数', name: 'lishu',width:100 , align:'left'},
			{ display: '发生率%', name: 'fashenglv',width:100 },
			{ display: '副反应',columns:
                [
                	{ display: '发生时已服此药(月份)',name: 'yuefen',columns:
                		[
                			{ display: '<3', width:50 ,render: function(record){
                					if(record.yuefen<=3){
                						return record.yuefen;
                					}
                				}
                			},
                			{ display: '3~6', width:50 ,render: function(record){
                					if(record.yuefen>3&&record.yuefen<=6){
                						return record.yuefen;
                					}
                				}
                			},
                			{ display: '6~12', width:50 ,render: function(record){
                					if(record.yuefen>6&&record.yuefen<=12){
                						return record.yuefen;
                					}
                				}
                			},
                			{ display: '12~24', width:50 ,render: function(record){
                					if(record.yuefen>12&&record.yuefen<=24){
                						return record.yuefen;
                					}
                				}
                			},
                			{ display: '24~36', width:50 ,render: function(record){
                					if(record.yuefen>24&&record.yuefen<=36){
                						return record.yuefen;
                					}
                				}
                			},
                			{ display: '>36', width:50 ,render: function(record){
                					if(record.yuefen>36){
                						return record.yuefen;
                					}
                				}
                			}
                		] 
                	},
                	{ display: '同时服药',columns:
                		[
                			{ display: '有', name: 'you', width:50 },
                			{ display: '无', name: 'wu', width:50 }
                		]  
                	}
                ]
			},
			{ display: '备注', name: 'beizhu',width:100, type: 'string', editor: { type: 'string'} }
		]
	});
	
	//per
	per = $("#per").ligerGrid({
		url: _url, width: '750', height:'325',enabledSort:false,async:false,delayLoad:true,pageSize:100,
		usePager: true, rownumbers: true, alternatingRow: true,
		columns: [
			{ display: 'tbe_id', name: 'tbe_id', hide: true, width:1 },
			{ display: '产品名称', name: 'tmad_name', width: 100, align: 'left' },			
			{ display: '生产企业', name: 'tmad_company_name', width: 100, align: 'left' },
			{ display: '批号', name: 'tmad_batch_code', width: 70, align: 'left' },
			{ display: '姓名', name: 'tbe_name', width: 70, align: 'left' },
			{ display: '身份证号', name: 'tbe_idcard', width: 160, align: 'left' },
			{ display: '性别', name: 'tbe_sex', width: 70, align: 'left' },
			{ display: '副反应', name: 'tmgd_code', width: 1, hide: true, align: 'left' },
			{ display: '使用时间', name: 'tmamvm_lmedicine_time', width: 70, align: 'left' },
			{ display: '同时用药', name: 'tmamvd_same_pharmacy_des', width: 70, align: 'left' ,render: function(record, index, value, oth){
					return record.tmamvd_same_pharmacy_des=="1"?"是":"否";
				}
			}
		]
	});
	
	$("#serbtn").click(function(){
		$(this).hide();
		$("#his").show();		
		$("#his1").hide();
		var jsonObj = {};
    	jsonObj.Rows = [];
    	manager.set({ data: jsonObj });
		$("#hisnian").find("option").remove();
		$("#hisnian").append('<option value=""></option>');
		var param = {
			"classname": "com.wxtf.platform.main.report.TmaMedicineVistorReport",
			"methodname": "selectYear",
			"logicdata": [],
			"extenddata": []
		};
		callserver(param, function(data, satus){
			$.each(data, function (i, item) {
        		 $("#hisnian").append('<option value="'+item.nian+'">'+item.nian+'</option>');
        	}); 
		},function(data, satus){
			warningTip(data.resultrecord);
		});
	});
	$("#hisnian").change(function(){
		var v = $("#hisnian").val();
		$("#hisjidu").find("option").remove();
		var param = {
			"classname": "com.wxtf.platform.main.report.TmaMedicineVistorReport",
			"methodname": "selectQuarter",
			"logicdata": [],
			"extenddata": []
		};
		param.logicdata = '[{"jidu":"'+v+'"}]';
		callserver(param, function(data, satus){
			$.each(data, function (i, item) {
        		 $("#hisjidu").append('<option value="'+item.nian+'">'+item.nian+'</option>');
        	}); 
		},function(data, satus){
			warningTip(data.resultrecord);
		});
	});
	$("#selbtn").click(function(){
		var v1 = $("#hisnian").val();
		var v2 = $("#hisjidu").val();
		var v3 = v1+"-"+v2;
		if('' == v1){warningTip("请选择年"); return;}
		var param = {
			"classname": "com.wxtf.platform.main.report.TmaMedicineVistorReport",
			"methodname": "selectHistory",
			"logicdata": [],
			"extenddata": []
		};
		param.logicdata = '[{"jidu":"'+v3+'"}]';
		manager.setOptions({url:_url,parms: param});
		var param = {
			"classname": "com.wxtf.platform.main.report.TmaMedicineVistorReport",
			"methodname": "selectCreateByAndCreateTime",
			"logicdata": [],
			"extenddata": []
		};
		param.logicdata = '[{"jidu":"'+v3+'"}]';
		callserver(param, function(data, satus){
			$.each(data, function (i, item) {
        		 $("#tianbaoren").val(item.CREATE_BY);
        		 $("#tianbaoriqi").val(item.CREATE_TIME);
        	}); 
		},function(data, satus){
			warningTip(data.resultrecord);
		});
	});
});
/*
*季度
*/
function quarter(q){
	var time = q.substring(q.indexOf("-")+1,q.lastIndexOf("-"));
	var temp = q.substring(0,q.indexOf("-"))+"-";
	if(time<=3){
		temp += "1";
	}else if(time>3 &&time<=6){
		temp += "2";
	}else if(time>6&&time<=9){
		temp += "3";
	}else if(time>9&&time<=12){
		temp += "4";
	}
	$("#r_quarter").val(temp);
}
/*
*例数
*/
function personLiShu(record){
	initWindowByDiv2('per-div', '人员', 780, 400, closeWin);
	//定义的参数
	var param = {
		"classname": "com.wxtf.platform.main.report.TmaMedicineVistorReport",
		"methodname": "selectPerson",
		"logicdata": [],
		"extenddata": []
	};
	param.logicdata = '[{"tmad_id":"'+record.tmad_id+'","tmgd_code":"'+record.tmgd_code+'"}]';
	per.setOptions({url:_url,parms: param});
}
/*
*服药人数
*/
function person(record){
	initWindowByDiv2('per-div', '人员', 780, 400, closeWin);
	//定义的参数
	var param = {
		"classname": "com.wxtf.platform.main.report.TmaMedicineVistorReport",
		"methodname": "selectPerson",
		"logicdata": [],
		"extenddata": []
	};
	param.logicdata = '[{"tmad_id":"'+record.tmad_id+'","tmgd_code":""}]';
	per.setOptions({url:_url,parms: param});
}
/*
*确认上报
*/
function doReport(){
	var r_is_valid = $("#r_is_valid").val();
	var tianbaoren = $("#tianbaoren").val();
	var r_quarter = $("#r_quarter").val();
	//定义参数
	var param = {
		"classname": "com.wxtf.platform.main.report.TmaMedicineVistorReport",
		"methodname": "",
		"logicdata": [],
		"extenddata": []
	};
	param.methodname = "isReport";
	param.logicdata = '[{"r_quarter":"'+r_quarter+'"}]';
	callserver(param, function(data, textStatus){
		if(data.resultrecord > 0){
			succMsgTip("已上报");
			return;
		}
		if(JSON.stringify(manager.getData())=="[]"){
			succMsgTip("没有要上报的数据");
			return;
		}
		param.methodname = "save";
		param.logicdata = '[{"r_quarter":"'+r_quarter+'","tianbaoren":"'+tianbaoren+'","r_is_valid":"'+r_is_valid+'",ids:'+JSON.stringify(manager.getData())+'}]';
		callserver(param, ajaxCallbackSuccFunc, ajaxCallbackErrorFunc);
	}, ajaxCallbackErrorFunc);
	
}
/*
 * 导出
 */
function expData(){
	var tianbaoriqi = $("#tianbaoriqi").val();
	var tianbaoren = $("#tianbaoren").val();
	var tianbaojigou = $("#tianbaojigou").val();
	var param = {
		"classname": "com.wxtf.platform.main.report.TmaMedicineVistorReport",
		"methodname": "expData",
		"logicdata": [],
		"extenddata": []
	};
	param.logicdata = '[{"tianbaojigou":"'+tianbaojigou+'","tianbaoriqi":"'+tianbaoriqi+'","tianbaoren":"'+tianbaoren+'",ids:'+JSON.stringify(manager.getData())+'}]';
	callserver(param, function(data, textStatus){
		if(data.result){
			downloadFile(data.resultrecord);
		} else {
			warningTip(data.resultrecord);
		}
	}, function(data, textStatus){
	});
}
/*
 * ajax成功回调
 */
function ajaxCallbackSuccFunc(data, textStatus){
	if(data.resultrecord.length>5){
		$.ligerDialog.warn(data.resultrecord);
	}else{
		succMsgTip(data.resultrecord);
	}
}

/*
 * ajax失败回调
 */
function ajaxCallbackErrorFunc(data, textStatus){
	succMsgTip(data.resultrecord);
}
</script>
</head>
	<body>
	<input type="hidden" id="r_quarter" name="r_quarter" />
	<div id="per-div" style=" display:  none;">
		<div id="per"></div>
	</div>
	<div>
		<span id="his1">
		<%
		if(!"1".equals(org_id)){
		%>
		是否上报：
		<select id="r_is_valid" name="tmascm_is_valid" style=" width: 100px;">
			<option value="1" selected="selected">是</option>
			<option value="0">否</option>
		</select>
		<input class="btn2" value="确认" type="button" onclick="doReport();" />
		<%
		}
		%>
		</span>
		<input class="btn2" value="导出" type="button" onclick="expData();" />
		<input class="btn2" id="serbtn" value="查询" type="button"/>
		<span id="his" style="display: none;">
			<select id="hisnian" name="hisnian" style=" width: 80px;height: 20px;">
			</select>年
			<select id="hisjidu" name="hisjidu" style=" width: 80px;height: 20px;">
			</select>季度
			<input class="btn2" id="selbtn" value="搜索" type="button" />
		</span>		
	</div>
	<table style=" width: 100%;">
		<tr>
			<td colspan="12" align="center"><h1>育龄妇女使用避孕药随访汇总表</h1></td>
		</tr>
		<tr>
			<td colspan="12">
				<table>
					<tr>
						<td align="left">填报单位名称(公章)：</td>
						<td align="left"><input readonly="readonly" name="tianbaojigou" id="tianbaojigou"/></td>
						<td>
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						</td>
						<td align="right">填报日期：</td>
						<td align="left"><input readonly="readonly" name="tianbaoriqi" id="tianbaoriqi"/></td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td colspan="12"><div id="grid"></div></td>
		</tr>
		<tr>
			<td colspan="12" align="right">填报人:<input readonly="readonly" name="tianbaoren" id="tianbaoren"/></td>
		</tr>
		<tr>
			<td>代码</td>
			<td>副反应</td>
			<td>代码</td>
			<td>副反应</td>
			<td>代码</td>
			<td>副反应</td>
			<td>代码</td>
			<td>副反应</td>
			<td>代码</td>
			<td>副反应</td>
			<td>代码</td>
			<td>副反应</td>
		</tr>
		<tr>
			<td>01</td>
			<td>痛经</td>
			<td>03</td>
			<td>经期延长</td>
			<td>05</td>
			<td>月经量增多</td>
			<td>07</td>
			<td>恶心</td>
			<td>09</td>
			<td>下腹痛</td>
			<td>11</td>
			<td>妊娠</td>
		</tr>
		<tr>
			<td>02</td>
			<td>少量出血/点滴出血</td>
			<td>04</td>
			<td>月经周期改变</td>
			<td>06</td>
			<td>月经量减少</td>
			<td>08</td>
			<td>呕吐</td>
			<td>10</td>
			<td>腰背酸痛</td>
			<td>12</td>
			<td>贫血</td>
		</tr>
	</table>
	</body>
</html>
